from selenium import webdriver
from time import sleep

driver = webdriver.Chrome()

# 对日期输入框的更改（包含readonly）
# driver.get("https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=12306&fenlei=256&oq=clientHeight%25E7%25BF%25BB%25E8%25AF%2591&rsv_pq=e880189a000a376e&rsv_t=2ac7AzG4qTsUpU7I8pjEC005hOyDDfTHPanqg%2BsljV2%2FKd53Ah3shNhCcJU&rqlang=cn&rsv_dl=tb&rsv_enter=0&rsv_btype=t&inputT=4553&rsv_sug3=33&rsv_sug1=27&rsv_sug7=101&prefixsug=12%2526lt%253B06&rsp=0&rsv_sug4=4553")
# # js脚本执行操作
# js1 = "document.getElementsByClassName('op-ly_ticket_train-ipt-date')[0].value='0101010'"
# # 删除readonly属性再操作
# js2 = "document.getElementsByClassName('op-ly_ticket_train-ipt-date')[0].removeAttribute('readonly')"
# driver.execute_script(js2)
# driver.find_element_by_class_name('op-ly_ticket_train-ipt-date').clear()
# driver.find_element_by_class_name('op-ly_ticket_train-ipt-date').send_keys("0010120")

# 移除target元素
driver.get("https://www.baidu.com/")
# remove = "document.querySelector('#s-top-left > a:nth-child(1)').removeAttribute('target')"
# driver.execute_script(remove)
# driver.find_element_by_link_text('新闻').click()

# 添加元素
driver.get("https://www.baidu.com/")
driver.find_element_by_id("kw").send_keys("1")
driver.find_element_by_id("su").click()
add = "document.getElementsByClassName('toindex')[0].target='_blank'"
driver.execute_script(add)
driver.find_element_by_link_text("百度首页").click()

sleep(3)
driver.quit()

